package com.gaofans.nrpc.common.serializer.kryo;

import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import com.esotericsoftware.kryo.util.Pool;
import com.gaofans.nrpc.common.serializer.Serializer;
import com.gaofans.nrpc.common.serializer.SerializerBuilder;

import java.util.Objects;

/**
 * @author GaoFans
 */
public class KryoSerializerBuilder implements SerializerBuilder {

    private Pool<Kryo> kryoPool;
    private Pool<Output> outputPool;
    private Pool<Input> inputPool;

    public KryoSerializerBuilder kryoPool(Pool<Kryo> kryoPool){
        this.kryoPool = Objects.requireNonNull(kryoPool);
        return this;
    }

    public KryoSerializerBuilder outputPool(Pool<Output> outputPool){
        this.outputPool = Objects.requireNonNull(outputPool);
        return this;
    }

    public KryoSerializerBuilder inputPool(Pool<Input> inputPool){
        this.inputPool = Objects.requireNonNull(inputPool);
        return this;
    }



    @Override
    public Serializer build() {
        Objects.requireNonNull(kryoPool);
        Objects.requireNonNull(outputPool);
        Objects.requireNonNull(inputPool);
        return new KryoSerializer(kryoPool,outputPool,inputPool);
    }

    @Override
    public byte type() {
        return 1;
    }
}
